package com.example.myapplication.util;


import com.mysql.jdbc.Connection;

import java.sql.DriverManager;
import java.sql.SQLException;

public class MySQLConnection {
    static String CLS = "com.mysql.jdbc.Driver";
    private static final String URL = "jdbc:mysql://10.0.2.2:3306/ydmanage?useUnicode=true&characterEncoding=utf-8";
    private static final String USER = "root";
    private static final String PASSWORD = "root";

    static {
        try {
            Class.forName(CLS);
        } catch (Exception e) {
            System.out.println("加载驱动错误");
        }
    }

    public static Connection getConnection() {
        try {
            return (Connection) DriverManager.getConnection(URL, USER, PASSWORD);
        } catch (Exception throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    public static void closeConnection(Connection conn) throws SQLException {
        if (conn != null) {
            conn.close();
        }
    }
}